package netutil

import (
	"net"
)

// 获取本地地址
func GetLocalIP4() (ip string) {
	// 设定默认ip
	ip = "127.0.0.1"
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return
	}
	for _, address := range addrs {
		if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
			if ipNet.IP.To4() != nil {
				ip = ipNet.IP.String()
			}
		}
	}
	return
}
